<template>
  <div class="login">
    <div class="login-box">
      <el-form :model="signForm" ref="signForm" :rules="rules" :status-icon="true">
        <h3>系统注册</h3>
        <el-form-item prop="mobile">
          <el-input v-model="signForm.mobile">
            <template slot="prepend" width="150">
              用户名
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password1">
          <el-input v-model="signForm.password1" type="password">
            <template slot="prepend">密&nbsp;&nbsp;&nbsp;码</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password2">
          <el-input v-model="signForm.password2" type="password">
            <template slot="prepend">密&nbsp;&nbsp;&nbsp;码</template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width:100%;" @click="check('signForm')">注册</el-button>
        </el-form-item>
        <el-form-item style="text-align:right">
          <router-link to="/login">登陆</router-link>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'Login',
    data() {
      return {
        signForm: {
          mobile: '',
          password1: '',
          password2: ''
        },
        rules: {
          mobile: [{
            required: true,
            message: '请输入用户名',
            trigger: 'change'
          }],
          password1: [{
            required: true,
            message: '请输入密码',
            trigger: 'change'
          }],
          password2: [{
            required: true,
            message: '请输入密码',
            trigger: 'change'
          }]
        }

      }
    },
    methods: {
      check(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$http.post('/user/registration/', this.signForm).then(
              response => {
                this.$router.push({
                  path: '/Login'
                })
                this.$message('注册成功')
              }
            )
          } else {
            console.log('error submit!!');
            return false;
          }
        })
      }
    }
  }

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang=scss scoped>
  .login {
    height: 100%;

    .login-box {
      width: 50%;
      max-width: 600px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      box-sizing: border-box;
      box-shadow: 0 0 25px #cac6c6;
      border: 1px solid #eaeaea;
      padding: 35px 35px 15px;
    }
  }

</style>
